package com.vincent.suchao.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.vincent.suchao.entity.TeamMembers;
import com.vincent.suchao.entity.TeamMembers.Member;
import com.vincent.suchao.lcld.R;

public class MembersAdapter extends BaseAdapter {

	private Context context;
	private LayoutInflater mInflater;
	TeamMembers members;

	public MembersAdapter(Context mcontext) {
		super();
		this.context = mcontext;
		this.mInflater = LayoutInflater.from(context);
		this.members = new TeamMembers(mcontext);
	}

	@Override
	public int getCount() {
		return members.getMembers().size();
	}

	@Override
	public Object getItem(int position) {
		return members.getMembers().get(position);
	}

	@Override
	public long getItemId(int position) {
		return 0;
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		Member member = (Member) members.getMembers().get(position);

		MyHolder holder;
		if (convertView == null) {
			convertView = mInflater.inflate(R.layout.inflater_member, null);
			holder = new MyHolder();

			holder.rl_inflater_member = (RelativeLayout) convertView.findViewById(R.id.rl_inflater_member);
			holder.iv_member1 = (ImageView) convertView.findViewById(R.id.iv_member1);
//			holder.iv_member2 = (ImageView) convertView.findViewById(R.id.iv_member2);
			convertView.setTag(holder);
		} else {
			holder = (MyHolder) convertView.getTag();
		}

//		if (position % 2 == 0) {
//			holder.iv_member1.setVisibility(View.VISIBLE);
//			holder.iv_member2.setVisibility(View.GONE);
//		} else {
//			holder.iv_member1.setVisibility(View.GONE);
//			holder.iv_member2.setVisibility(View.VISIBLE);
//		}
		holder.rl_inflater_member.setTag(R.id.rl_inflater_member, member);
		holder.iv_member1.setImageResource(member.getResID());
//		holder.iv_member2.setImageResource(member.getResID());
		return convertView;
	}

	class MyHolder {
		RelativeLayout rl_inflater_member;
		ImageView iv_member1;
		ImageView iv_member2;
	}

}
